<template>
  <div class="h-1/2">
    <CommonCard title="预警情况">
      <template #content>
        <div class="flex flex-col gap-[6px]">
          <div class="item">
            <div class="flex items-center">
              <img src="@/assets/image/yjzs.png" alt="" />
              <span class="text-[12px] text-[#d3d4d4]">待审核预警数</span>
            </div>
            <div class="text-[18px] font-[Bebas]">{{ dshCount }}</div>
          </div>
          <div class="item">
            <div class="flex items-center">
              <img src="@/assets/image/dclyjs.png" alt="" />
              <span class="text-[12px] text-[#d3d4d4]">待推送预警数</span>
            </div>
            <div class="text-[18px] font-[Bebas]">{{ dtsCount }}</div>
          </div>
          <div class="item">
            <div class="flex items-center">
              <img src="@/assets/image/jjgjs.png" alt="" />
              <span class="text-[12px] text-[#d3d4d4]">已推送预警数</span>
            </div>
            <div class="text-[18px] font-[Bebas]">{{ ytsCount }}</div>
          </div>
        </div>
      </template>
    </CommonCard>
  </div>
</template>
<script lang="ts" setup>
import { warningStatusCount } from '@/api/home'
import CommonCard from '@/components/CommonCard.vue'
import { useCommonStore } from '@/stores/common'
import { timeNum } from '@/utils/commonFn'
import { onMounted, onUnmounted, ref, watch } from 'vue'
const dshCount = ref(0)
const dtsCount = ref(0)
const ytsCount = ref(0)
const timer = ref()
const formData = ref({
  institutionId: sessionStorage.getItem('institutionId')
})
watch(
  () => useCommonStore().institutionId,
  (value) => {
    formData.value.institutionId = value
    getInfo()
  }
)
const getInfo = async () => {
  const res: any = await warningStatusCount(formData.value)
  res.data.forEach((item: any) => {
    if (item.status === '1') {
      dshCount.value = item.count
    }
    if (item.status === '2') {
      dtsCount.value = item.count
    }
    if (item.status === '3') {
      ytsCount.value = item.count
    }
  })
}
onMounted(() => {
  getInfo()
  timer.value = setInterval(() => {
    getInfo()
  }, timeNum)
})
onUnmounted(() => {
  clearInterval(timer.value)
})
</script>

<style scoped lang="less">
.item {
  width: 100%;
  height: 40px;
  display: flex;
  justify-content: space-between;
  background: linear-gradient(90deg, rgba(0, 113, 242, 0.2) 0%, rgba(0, 113, 242, 0) 100%);
  position: relative;
  align-items: center;
  &::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    width: 4px;
    height: 40px;
    background: #0071f2;
  }
  img {
    width: 28px;
    height: 28px;
    margin-left: 16px;
    margin-right: 10px;
  }
}
</style>
